<?php
/**
 * Created by PhpStorm.
 * User: Eric
 * Email: 13522679763@163.com
 * Date: 2018/3/12
 * Time: 14:05
 */
namespace app\admin\model;
use think\Model;
class Technics extends Model
{

    //获取列表
    function index($name){
//        $goods_classify=Db('goods_classify');
//        $goods=Db('goods');
        if($name){
            $result=$this->where('name','like', '%' .$name. '%')->order('sort desc')->select();
        }else{
            $result=$this->where('status','neq',0)->order('sort desc')->select();
        }
        if ($result) {
           //  foreach($list as $k=>$v){
              //   $ids = $goods_classify->where(array('classify_id'=>$v['id']))->column('goods_id');
//                 if($ids){
//                     $v['goods_count'] = $goods->where(array('id'=>array('in',$ids),'status'=>array('neq',0)))->count();
//                 }else{
//                     $v['goods_count'] =0;
//                 }
            //     $list[$k]=$v;
//             }
            $data['count'] = $count=count($result);
            $data['list']  = $result;
            return $data;
        } else {
            return [];
        }
    }

    //添加
    function add($data)
    {
        $result = $this->isUpdate(false)->allowField(true)->save($data);
        if ($result) {
            return $this->id;
        } else {
            return false;
        }
    }
    //编辑  删除
    function edit($data){
        $result = $this->isUpdate(true)->allowField(true)->save($data);
        return $result;
    }

}